'''============================
@Time : 2024/1/13 13:32
@Author : YangLiHua
@File : login_page.py
@Desc : 
============================'''
from selenium.webdriver.common.by import By
from time import sleep

class LoginPage:
    def __init__(self,driver):
        # 登录
        self.account_elem=By.ID,'account'
        self.password_elem=By.NAME,'password'
        self.login_elem=By.ID, 'submit'
        # 退出登录
        self.quit_iframe=By.XPATH, '//*[@id="appIframe-my"]'
        # 点击头像
        self.quit_head_sculpture=By.XPATH, '//*[@id="userDropDownMenu"]/a/div/span'
        # 点击退出
        self.quit_text=By.XPATH, '//*[@id="userDropDownMenu"]/ul/li[14]/a'
        self.driver=driver

    def input_username(self,username):
        self.driver.find_element(*self.account_elem).clear()
        self.driver.find_element(*self.account_elem).send_keys(username)

    def input_password(self,password):
        self.driver.find_element(*self.password_elem).clear()
        self.driver.find_element(*self.password_elem).send_keys(password)

    def click_login(self):
        self.driver.find_element(*self.login_elem).click()

    def click_logout(self):
        # sleep(2)
        # 切换iframe
        iframe_my = self.driver.find_element(*self.quit_iframe)
        self.driver.switch_to.frame(iframe_my)
        # 点击头像
        self.driver.find_element(*self.quit_head_sculpture).click()
        # 点击退出
        self.driver.find_element(*self.quit_text).click()
        self.driver.switch_to.default_content()
